import requests


def get_ip():
    kdl_url = 'https://dps.kdlapi.com/api/getdps/?secret_id=ozt7trq2rp5yuip2hypz&signature=j5ta148mk1mjkw7vyzys3600miv3x09h&num=1&format=json&sep=1'
    ip = requests.get(kdl_url).json()["data"]["proxy_list"][0]
    proxies = {
        'http': f'http://d2262624099:8bnrqo2g@{ip}',
        'https': f'http://d2262624099:8bnrqo2g@{ip}'
    }
    return proxies


proxies = get_ip()
try:
    response = requests.get('http://httpbin.org/ip', proxies=proxies)
    print(response.content.decode())
except:
    print("代理IP失效")
    proxies = get_ip()
